package com.weng.bigdata.micro.service.warehouse.adapter.feign;

import com.weng.bigdata.micro.service.common.ServicesConstants;
import com.weng.bigdata.core.warehouse.model.dto.TableDto;
import com.weng.bigdata.micro.service.warehouse.adapter.fallback.WarehouseSchemaFallBack;
import com.weng.bigdata.micro.service.warehouse.adapter.model.req.AlterTableReq;
import com.weng.bigdata.micro.service.warehouse.adapter.model.req.CreateTableLikeReq;
import com.weng.framework.core.model.ResponseData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * 数仓适配schema管理
 * @author wengzhonghui
 * @date 2019/3/23 16:09
 */
@FeignClient(name = ServicesConstants.WAREHOUSE_ADAPTER_API_SERVER_NAME, fallback = WarehouseSchemaFallBack.class, configuration = WarehouseSchemaFallBack.class)
public interface WarehouseSchemaFeignService {

		String URL_PREFIX = "/schema";


		/**
		 * 创建表
		 * @param tableSchema
		 * @return
		 */
		@PostMapping(URL_PREFIX + "/table/create")
		ResponseData createTables(@RequestBody TableDto tableSchema);

		/**
		 * 根据源表名创建一个同样结构的表
		 * @param tableSchema 需要tbName属性即可, storedFormat存储格式可为空
		 * @return
		 */
		@PostMapping(URL_PREFIX + "/table/create/like")
		ResponseData createTableOfLike(@RequestBody CreateTableLikeReq tableSchema);

		@PutMapping(URL_PREFIX + "/table/alter")
		public ResponseData changeTableName(@RequestBody AlterTableReq alterTableReq);

		@DeleteMapping(URL_PREFIX + "/table/{tableName}/drop")
		ResponseData dropTables(@PathVariable("tableName") String tableName);

		/**
		 * 获取所有列
		 * @param tableName 表名, convertDbType 需要把列字段类型转换为对应的数据库类型
		 * @return
		 */
		@GetMapping(URL_PREFIX + "/{tableName}/columns")
		ResponseData getColumns(@PathVariable("tableName") String tableName, String convertDbType);

		/**
	 * 检查表是否存在
	 * @param tableName
	 * @return
	 */
		@GetMapping(URL_PREFIX + "/{tableName}/isExists")
		ResponseData checkTableIsExists(@PathVariable("tableName") String tableName);


}
